package com.pacage;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HelloServlet2 extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        System.out.println("重写了init出书实话的方法，做了一些工作");
    }

    /**
     * 在get请求调用
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("HelloServlet2 的doGet方法");
        ServletConfig servletConfig=getServletConfig();
        System.out.println(servletConfig);
        //1.乐意获取Servlet程序的别名servlet-name的值
        System.out.println("HelloServlet程序的别名是;"+servletConfig.getServletName());
        //2.获取初始化参数init.param
        System.out.println("初始化username的值是;"+servletConfig.getInitParameter("username"));
        System.out.println("初始化url的值是;"+servletConfig.getInitParameter("url"));
        //3.获取Servlet对象
        System.out.println(servletConfig.getServletContext());
    }

    /**
     * 在post请求调用
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Helloservlet2 的doPost方法");
        ServletConfig servletConfig=getServletConfig();
        System.out.println(servletConfig);
    }
}
